package kechengsheji.admin;

import MeetingRoom.MeetingRoomDAO;
import gongju.fuzhiqu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class AdminEditPanel extends JInternalFrame {

    public AdminEditPanel(Object id) {
        super("添加会议室", true, true, true, true);
        this.setVisible(true);

        JPanel panel = new JPanel();
        panel.setBackground(Color.WHITE);
        this.add(panel);

        Box box = Box.createVerticalBox();
        panel.add(box);
        box.add(Box.createVerticalStrut(55));

        Box box1 = Box.createHorizontalBox();
        box1.add(new JLabel("室名"));
        JTextField field1 = new JTextField(10);
        box1.add(field1);
        box.add(box1);
        box.add(Box.createVerticalStrut(15));

        Box box2 = Box.createHorizontalBox();
        box2.add(new JLabel());
        JComboBox<String> field2 = new JComboBox<>();
        box2.add(field2);
        field2.addItem(fuzhiqu.weixiuing);
        field2.addItem(fuzhiqu.weixiuok);
        field2.addItem(fuzhiqu.weixiunot);
        box.add(box2);
        box.add(Box.createVerticalStrut(15));

        Box box3 = Box.createHorizontalBox();
        box1.add(new JLabel());
        JComboBox<String> field3 = new JComboBox<>();
        box3.add(field3);
        field3.addItem(fuzhiqu.Open);
        field3.addItem(fuzhiqu.Close);
        box.add(box3);
        box.add(Box.createVerticalStrut(15));

        if(id!=null){
            Object[] data = MeetingRoomDAO.findById(id);
        }

        JButton btn = new JButton("提交");
        Box boxBtn = Box.createHorizontalBox();
        boxBtn.add(Box.createHorizontalStrut(40));
        boxBtn.add(btn);
        box.add(boxBtn);

        btn.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                Object[] data = new Object[]{id, field1.getText(), field2.getSelectedItem(), field3.getSelectedItem()};
               if(id==null){
                   MeetingRoomDAO.add(data);
               }else{
                   MeetingRoomDAO.updata(id,data);
               }
               Adminpanel.setContent(new AdminTablePanel());
            }
        });
    }
}
